package actor

import "sync"

type Queue struct {
	msgChan []Msg
	lock    sync.Mutex
}

func (q *Queue) Push(msg Msg) {
	q.lock.Lock()
	defer q.lock.Unlock()
	q.msgChan = append(q.msgChan, msg)
}

func (q *Queue) Pop() (Msg, bool) {
	q.lock.Lock()
	defer q.lock.Unlock()
	if len(q.msgChan) > 0 {
		msg := q.msgChan[0]
		q.msgChan = q.msgChan[1:]
		return msg, true
	}
	return Msg{}, false
}

func (q *Queue) Len() int {
	q.lock.Lock()
	defer q.lock.Unlock()
	return len(q.msgChan)
}
